package scene;

import javax.media.opengl.GL;

public abstract class AbstractCamera {


	String name="no name";

	float eyeX;
	float eyeY;
	float eyeZ;

	float lookAtX;
	float lookAtY;
	float lookAtZ;

	final float TRESPETIT = 0.0000006f;

	final float DEUXPI = (float) (Math.PI*2);

	protected float angleDeRotationCamera=(float) (DEUXPI/360*1);

	float upX;
	float upY;
	float upZ;

	float rayon;

	private MouseHandler mouseHandler;
	private KeyHandler keyHandler;

	private GLScene3D glscene3d;

	private boolean isStereo = false;
	private boolean typeOeil = false;

	public AbstractCamera(GLScene3D _glscene3d, float origineX, float origineY, float origineZ,
			float lookAtX, float lookAtY, float lookAtZ)
	{

		this(_glscene3d);
		setEyeXYZ(origineX,origineY,origineZ);
		setLookAtX(lookAtX);
		setLookAtY(lookAtY);
		setLookAtZ(lookAtZ);

	}

        
	/**
	 * cette cam�ra est affect�e a une sc�ne
	 * donn�e
	 * @param _glscene3d
	 */
	public AbstractCamera(GLScene3D _glscene3d)
	{
		/**
		 * pr�ciser la sc�ne dans laquelle la cam�ra se trouve
		 */
		this.setGlscene3d(_glscene3d);
		/**
		 * initialiser le vecteur direction
		 *
		 */
		setUpX(0);
		setUpY(1);
		setUpZ(0);

	}

	/**
	 * @param x
	 * @param y
	 * @param z
	 */
	protected void setEyeXYZ(float x, float y, float z)
	{
		setEyeX(x);
		setEyeY(y);
		setEyeZ(z);


		/**
		 * on d�finit rayon, rho et theta
		 */
        //calcTheta();
        //calcRho();
        calculerRayon();




	}


	/**
	 * @param x
	 * @param y
	 * @param z
	 */
	protected void setCentreXYZ(float x, float y, float z)
	{
		setLookAtX(x);
		setLookAtY(y);
		setLookAtZ(z);


		/**
		 * on d�finit rayon, rho et theta
		 */
        //calcTheta();
        //calcRho();
        calculerRayon();




	}


	/**
	 * @return the eyeX
	 */
	protected float getEyeX() {
		return eyeX;
	}
	/**
	 * @param eyeX the eyeX to set
	 */
	private void setEyeX(float _eyeX) {
		if(_eyeX==0) this.eyeX=TRESPETIT; else
		this.eyeX = _eyeX;
	}
	/**
	 * @return the eyeY
	 */
	protected float getEyeY() {
		return eyeY;
	}
	/**
	 * @param eyeY the eyeY to set
	 */
	private void setEyeY(float _eyeY) {
		if(_eyeY==0) this.eyeY=TRESPETIT; else
		this.eyeY = _eyeY;
	}
	/**
	 * @return the eyeZ
	 */
	protected float getEyeZ() {
		return eyeZ;
	}
	/**
	 * @param eyeZ the eyeZ to set
	 */
	private void setEyeZ(float _eyeZ) {
		if(_eyeZ==0) this.eyeZ=TRESPETIT; else
		this.eyeZ = _eyeZ;
	}
	/**
	 * @return the lookAtX
	 */
	protected float getLookAtX() {
		return lookAtX;
	}
	/**
	 * @param lookAtX the lookAtX to set
	 */
	protected void setLookAtX(float _lookAtX) {
		if(_lookAtX==0) this.lookAtX=TRESPETIT; else
		this.lookAtX = _lookAtX;
	}
	/**
	 * @return the lookAtY
	 */
	protected float getLookAtY() {
		return lookAtY;
	}
	/**
	 * @param lookAtY the lookAtY to set
	 */
	protected void setLookAtY(float _lookAtY) {
		if(_lookAtY==0) this.lookAtY=TRESPETIT; else
		this.lookAtY = _lookAtY;
	}
	/**
	 * @return the lookAtZ
	 */
	protected float getLookAtZ() {
		return lookAtZ;
	}
	/**
	 * @param lookAtZ the lookAtZ to set
	 */
	protected void setLookAtZ(float _lookAtZ) {
		if(_lookAtZ==0) this.lookAtZ=TRESPETIT; else
		this.lookAtZ = _lookAtZ;
	}
	/**
	 * @return the upX
	 */
	protected float getUpX() {
		return upX;
	}
	/**
	 * @param upX the upX to set
	 */
	private void setUpX(float upX) {
		this.upX = upX;
	}
	/**
	 * @return the upY
	 */
	protected float getUpY() {
		return upY;
	}
	/**
	 * @param upY the upY to set
	 */
	private void setUpY(float upY) {
		this.upY = upY;
	}
	/**
	 * @return the upZ
	 */
	protected float getUpZ() {
		return upZ;
	}
	/**
	 * @param upZ the upZ to set
	 */
	private void setUpZ(float upZ) {
		this.upZ = upZ;
	}

	/**
	 * positionner la cam�ra
	 * @param gl
	 */
	final public void positionner(GL gl)
	{




	        /**
	         * recadrage de la cam�ra sur la sc�ne
	         */
			this.getGlscene3d().getOrthogonalDisplay();

			/**
			 * si st�r�o!
			 */
			double xEye;
			final double IOD=0.04;

			if(this.isStereo())
			{

				if(this.isTypeOeil())
				{
					xEye=getEyeX()-IOD/2.0;

				}
				else
				{	xEye=getEyeX()+IOD/2.0;

				}



			}
			else
				xEye=this.getEyeX();


			/**
			 * positionner la cam�ra
			 */
	        Dessin.glu.gluLookAt(xEye, getEyeY(),
	                getEyeZ(), getLookAtX(),
	                getLookAtY(), getLookAtZ(),
	                getUpX(),
	                getUpY(),getUpZ());




	        /**
	         * une mise � jour de la position de la lumi�re
	         * attach�e � la cam�ra courante
	         *
	         */
	        updateLightCamera(gl,GL.GL_LIGHT0);





		}


	public void updateLightCamera(GL _gl, int light)
	{
		GL gl = _gl;

	    float[] lightPosition = {(getEyeX()-getLookAtX()),
	    		(getEyeY()-getLookAtY()),
	    		(getEyeZ()-getLookAtZ()),
	    		0.0f};


	    gl.glLightfv(light, GL.GL_POSITION, lightPosition,0);





	}
	/**
	 * @return the glscene3d
	 */
	protected GLScene3D getGlscene3d() {
		return glscene3d;
	}
	/**
	 * @param glscene3d the glscene3d to set
	 */
	protected void setGlscene3d(GLScene3D glscene3d) {
		this.glscene3d = glscene3d;
	}




public float getRayon() {

	return rayon;





}



public void setRayon(float rayon) {
	this.rayon = rayon;
}

/**
 * @return the name
 */
protected String getName() {

	return name;
}

/**
 * @param name the name to set
 */
protected void setName(String name) {
	this.name = name;
}

/**
 * @return the keyHandler
 */
protected KeyHandler getKeyHandler() {
	return keyHandler;
}

/**
 * @param keyHandler the keyHandler to set
 */
protected void setKeyHandler(KeyHandler keyHandler) {

	this.keyHandler = keyHandler;
}

/**
 * @return the mouseHandler
 */
protected MouseHandler getMouseHandler() {
	return mouseHandler;
}

/**
 * @param mouseHandler the mouseHandler to set
 */
protected void setMouseHandler(MouseHandler mouseHandler) {
	this.mouseHandler = mouseHandler;
}

protected float calculerRayon()
{
	return 0f;

}

protected void calcRho()
{


}

protected void calcTheta()
{

}

/**
 * @return the isStereo
 */
public boolean isStereo() {
	return isStereo;
}

/**
 * @param isStereo the isStereo to set
 */
public void setStereo(boolean isStereo) {
	this.isStereo = isStereo;
}

/**
 * @return the typeOeil
 */
public boolean isTypeOeil() {
	return typeOeil;
}

/**
 * @param typeOeil the typeOeil to set
 */
public void setTypeOeil(boolean typeOeil) {
	this.typeOeil = typeOeil;
}


}
